/*
 * Copyright (c) 2006-2020, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-09-29     Administrator       the first version
 */
#define LOG_TAG                        "w25qxx.c"
#define DBG_LVL                         DBG_LOG
#include <rtdbg.h>

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include "drv_spi.h"
#include "spi_flash_sfud.h"

#include <W25QXX/drv_spi_flash_w25qxx.h>

static int rt_hw_spi_flash_init(void)
{
    __HAL_RCC_GPIOF_CLK_ENABLE();
    rt_hw_spi_device_attach( W25QXX_SPI , W25QXX_SPI0 , GPIOF, GPIO_PIN_6);

    if (RT_NULL == rt_sfud_flash_probe( FAL_USING_NOR_FLASH_DEV_NAME , W25QXX_SPI0 ))
    {
        LOG_E("spi flash probe failed!\n");
        return -RT_ERROR;
    };

    return RT_EOK;
}
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);

//enum{
//    SFUD_W25QXX_DEVICE_INDEX = 0,
//};
//#define SFUD_FLASH_DEVICE_TABLE    { [SFUD_W25QXX_DEVICE_INDEX] = { .name = "W25Q128",.spi.name = "SPI5"}}

